package com.nursing.Dao;

import com.nursing.bean.Family;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface FamilyDao {
    @Select("SELECT * FROM family")
    List<Family> getAll();

    @Select("SELECT * FROM family WHERE id = #{id}")
    Family getById(Integer id);

    @Select("SELECT * FROM family WHERE elder_id = #{elderId}")
    List<Family> getByElderId(Integer elderId);

    @Insert("INSERT INTO family (elder_id, name, relationship, phone) " +
            "VALUES (#{elderId}, #{name}, #{relationship}, #{phone})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insert(Family family);

    @Update("UPDATE family SET name = #{name}, relationship = #{relationship}, phone = #{phone} WHERE id = #{id}")
    void update(Family family);

    @Delete("DELETE FROM family WHERE id = #{id}")
    void delete(Integer id);
}